package jsd2204.bookstore.bookserver.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import jsd2204.bookstore.bookserver.pojo.entity.Book;
import jsd2204.bookstore.bookserver.pojo.vo.BookRankingStandardVO;
import jsd2204.bookstore.bookserver.pojo.vo.BookStandardVO;
import jsd2204.bookstore.bookserver.pojo.vo.HostRandkingVO;
import jsd2204.bookstore.bookserver.pojo.vo.ReadTestStandardVO;
import jsd2204.bookstore.bookserver.service.impl.BookServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author jiale
 * @version 1.0
 * @description这是书籍的控制类
 * @date 2022/07/31 23:25
 **/
@Api(tags="书籍管理模块")
@Slf4j
@RestController
public class BookController {
    @Autowired
    private BookServiceImpl service;

    @GetMapping("/bookById")
    @ApiOperation("查询书籍信息")
    @ApiOperationSupport(order = 100)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "书籍的id", dataType = "long", required = true)
    })
    public BookStandardVO bookById(Long id) {
        BookStandardVO bookStandardVO = service.bookById(id);
        System.out.println(bookStandardVO);
        return bookStandardVO;
    }
    @GetMapping("/testById")
    @ApiOperation("查询书籍的试读内容信息")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "书籍的id", dataType = "long", required = true)
    })
    public ReadTestStandardVO testById(Long id) {
        ReadTestStandardVO readTestStandardVO = service.testById(id);
        return readTestStandardVO;
    }
    @GetMapping("/bookRandking")
    @ApiOperation("查询书籍销量排行情况")
    @ApiOperationSupport(order = 300)
    public List<BookRankingStandardVO> bookRandking(Long id) {
        log.debug("id:"+id);
        List<BookRankingStandardVO> randkingList = service.bookRanking(id);
        log.debug("randking:"+randkingList);
        return randkingList;
    }
    @GetMapping("/hostRandking")
    @ApiOperation("查询总书籍销量排行情况")
    @ApiOperationSupport(order = 400)
    public List<HostRandkingVO> hostRandking() {
        List<HostRandkingVO> hostRandkingVO = service.hostRandking();
        return hostRandkingVO;
    }
}
